package butines.core.math2d;


public class Vector2DUtils {

	public static Vector2D truncate(Vector2D vec, float limite) {
		float value = limite / vec.length();
		if (value < 1f) {
			vec.x = vec.x * value;
			vec.y = vec.y * value;
		}
		return vec;
	}
	
	public static Vector2D interpolation(Vector2D v1, Vector2D v2, float blend) {
		v1.x = (v1.x + (v2.x - v1.x) * blend);
		v1.y = (v1.y + (v2.y - v1.y) * blend);
	    return v1;
	}

	public static float distanceSq(Vector2D v1, Vector2D v2) {
		float dx = v2.x - v1.x;
		float dy = v2.y - v1.y;
		return dx * dx + dy * dy;
	}

	public static float distance(Vector2D v1, Vector2D v2) {
		float dx = v2.x - v1.x;
		float dy = v2.y - v1.y;
		return (float) Math.sqrt(dx * dx + dy * dy);
	}
	
	public static Vector2D multAdd(Vector2D c, Vector2D a, float b) {
		c.x = c.x + (a.x * b);
		c.y = c.y + (a.y * b);
		return c;
	}
	
	public static Vector2D add(Vector2D c, Vector2D a, Vector2D b) {
		c.x = a.x + b.x;
		c.y = a.y + b.y;
		return a;
	}
	
	public static Vector2D sub(Vector2D c, Vector2D a, Vector2D b) {
		c.x = a.x - b.x;
		c.y = a.y - b.y;
		return c;
	}
	
	public static Vector2D normalise(Vector2D vec) {
		float norm = 1.0f / vec.length();
		vec.x = vec.x * norm;
		vec.y = vec.y * norm;
		return vec;
	}
	
//	public Vector2D globalPointToLocalPoint(Vector2D globalPoint) {
//		float newX = forward.x * globalPoint.x + forward.y * globalPoint.y + (-position.dot(forward));
//		float newY = side.x    * globalPoint.x + side.y    * globalPoint.y + (-position.dot(side));
//		localPoint.set(newX, newY);
//		return localPoint;
//	}
//
//	public Vector2D globalPointToLocalVector(Vector2D globalVector) {
//		float newX = forward.x * globalVector.x + forward.y * globalVector.y;
//		float newY = side.x    * globalVector.x + side.y    * globalVector.y;
//		localVector.set(newX, newY);
//		return localVector;
//	}
//	
//	public Vector2D globalPointToGlobalPoint(Vector2D localPoint) {
//		float newX = forward.x * localPoint.x + side.x * localPoint.y + position.x;
//		float newY = forward.y * localPoint.x + side.y * localPoint.y + position.y;
//		globalPoint.set(newX, newY);
//		return globalPoint;
//	}
//	
//	public Vector2D globalPointToGlobalVector(Vector2D localVector) {
//		float newX = forward.x * localVector.x + side.x * localVector.y;
//		float newY = forward.y * localVector.x + side.y * localVector.y;
//		globalVector.set(newX, newY);
//		return globalVector;
//	}
	
}
